<?php
/* 网仓接口 */
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

@ini_set('display_errors',        2);
require(ROOT_PATH . 'includes/lib_wangcang.php');
require_once(ROOT_PATH . 'includes/lib_order.php');
require_once(ROOT_PATH . 'includes/cls_json.php');
$json = new JSON();

$action  = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';

$url = 'http://test.eggms.com/openapi/wangcang.php?time='.time();
$data['appkey'] = 'aab4fea140';
$data['user'] = 'wangcang';
$data['pass'] = 'wangcang123';

/* 修改订单状态 */
// $data['act'] = 'setOrderStatus';
// $data['vdata']['status'] = '130';
// $data['vdata']['orderSn'] = '2014121272340';
// $data['vdata'] = $json->encode($data['vdata']);
// $data = vpost($url, $data);

/* 修改商品条形码 */
// $data['act'] = 'setSkuToCode';
// $data['vdata']['count'] = '2';
// $data['vdata']['codes'][0]['sku'] = '1010016';
// $data['vdata']['codes'][0]['code'] = '9999999999999999999';
// $data['vdata']['codes'][1]['sku'] = '1010001';
// $data['vdata']['codes'][1]['code'] = '8888888888888888888';
// $data['vdata'] = $json->encode($data['vdata']);
// $data = vpost($url, $data);

/* 导入入库信息 */
// $data['act'] = 'pushStockIn';
// $data['vdata']['count'] = '2';
// $data['vdata']['stockIn']['stockInSn'] = '265432165481';
// $data['vdata']['stockIn']['addTime'] = time();
// $data['vdata']['stockIn']['stockId'] = '220038';
// $data['vdata']['stockIn']['source'] = '2';
// $data['vdata']['stockIn']['orderSn'] = '220038';
// $data['vdata']['stockIn']['skus'][0]['sku'] = '1010016';
// $data['vdata']['stockIn']['skus'][0]['qty'] = '89';
// $data['vdata']['stockIn']['skus'][1]['sku'] = '1010001';
// $data['vdata']['stockIn']['skus'][1]['qty'] = '12';
// $data['vdata'] = $json->encode($data['vdata']);
// $data = vpost($url, $data);

/* 导入出库信息 */
// $data['act'] = 'pushStockOut';
// $data['vdata']['count'] = '2';
// $data['vdata']['stockOut']['stockOutSn'] = '265432165481';
// $data['vdata']['stockOut']['addTime'] = time();
// $data['vdata']['stockOut']['stockId'] = '220038';
// $data['vdata']['stockOut']['source'] = '2';
// $data['vdata']['stockOut']['orderSn'] = '2014121272340';
// $data['vdata']['stockOut']['skus'][0]['sku'] = '1010016';
// $data['vdata']['stockOut']['skus'][0]['qty'] = '89';
// $data['vdata']['stockOut']['skus'][1]['sku'] = '1010001';
// $data['vdata']['stockOut']['skus'][1]['qty'] = '12';
// $data['vdata'] = $json->encode($data['vdata']);
// $data = vpost($url, $data);

// $data = vsetcancelBackTrade(array(2), $v_data);

// $data = vsetpushProducts(false, $v_data);
$data = vsetpushProducts(array(1659), $v_data);
// $data = vgettradeStatusQuery(array('2014111151641'), $v_data);
// $data = vsetpushTrades(array('13573'), $v_data);
// $data = vgetcancelTrade(array('2014112397260'), $v_data);
// $data = vgettradeQuery(array('2014112397260'), $v_data);
// $data = vgetinventoryQuery(1,$v_data);
// $data = vgettradeDeliverQuery(false, $v_data, 1, date('Y-m-d H:i:s', time()-3600000), date('Y-m-d H:i:s'));
// $m = new memcached();
// $m->addserver('127.0.0.1', 11211);
// $data = $m->get('wangcang');
// $data2 = $m->get('wangcangtime');
// $data3 = $m->get('wangcangip');

// $sql = "INSERT INTO " . $ecs->table('wcSkuToCode') . "(sku, code) " . " SELECT goods_sku,CONCAT('9999',goods_sku) AS code FROM " .  $ecs->table('goods_stock') . " WHERE area_id = 1";
// $db->query($sql);
/* 获取非13位条码 */
// $sql = "SELECT * FROM " . $ecs->table('wcSkuToCode') . " WHERE LENGTH(code) != 13";
// $data = $db->getAll($sql);
/* 生成条形码 */
// foreach ($data as $key => $value) {
//     $value['code'] = EAN13('69298787'.($key+1000));
//     $sql = "UPDATE " . $ecs->table('wcSkuToCode') . " SET code = $value[code], isBarcode = '0' WHERE sku = $value[sku]";
//     $db->query($sql);
// }
/* 过滤并查询不符要求的条形码 */
// $sql = "SELECT * FROM " . $ecs->table('wcSkuToCode');
// $data = $db->getAll($sql);
// foreach ($data as $key => $value) {
//     $code = EAN13(substr($value['code'],0,12));
//     if($code != $value['code']){
//         $sql = "UPDATE " . $ecs->table('wcSkuToCode') . " SET code = $code, isBarcode = '0' WHERE sku = $value[sku]";
//         $db->query($sql);
//         echo $value['sku']."<br />";
//     }
// }
echo "<pre>";
print_r($data);
echo "</pre>";
// echo "<pre>";
// print_r($data2);
// echo "</pre>";
// print_r($data3);

exit;

?>